package com.kiln.juxingqs.ui.vm

import android.app.Application
import android.text.TextUtils
import androidx.lifecycle.MutableLiveData
import client.global.commlib.network.data.JsonResult
import client.global.commlib.network.data.Ret
import client.global.commlib.toast.toast
import com.kiln.juxingqs.api.bean.GetPpRet
import com.kiln.juxingqs.ui.viewmodel.MiddleVm

class ApplyThViewModel(app: Application) : MiddleVm(app) {
    val forgetRet = MutableLiveData<JsonResult<Ret>>()
    val isShowing = MutableLiveData<Boolean>()

    val sNum = MutableLiveData<String>("")
    val name = MutableLiveData<String>("")
    val qu = MutableLiveData<String>("")
    val addr = MutableLiveData<String>("")
    val phone = MutableLiveData<String>("")
    val bath = MutableLiveData<GetPpRet.Deal>()
    val quIds = MutableLiveData<String>("")
    /**
     */
    fun ok() {
        if (TextUtils.isEmpty(sNum.value)
            || TextUtils.isEmpty(name.value)
            || TextUtils.isEmpty(addr.value)
            || TextUtils.isEmpty(phone.value)
            || TextUtils.isEmpty(qu.value)
        ) {
            toast("所有不能为空")
            return
        }
        val quIds = qu.value!!.split(" ")

        val sheng = quIds[0]
        val shi = quIds[1]
        val qu = quIds[2]
        hold({
            server.applyTh(
                "${bath.value!!.bath_id}",
                sNum.value!!,
                name.value!!,
                phone.value!!,
                addr.value!!,
                sheng,
                shi,
                qu,
            )
        }, {
            isShowing.value = true
        }, {
            forgetRet.value = it
        }, {}, {
            isShowing.value = false
        })
    }

}